<?php

//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionCore\Other;

/**
 * 回传设备管理
 *
 * @author Xmh
 */
class Equipment {

    private $Equipment;

    public function __construct() {
        $this->Equipment = M('Equipment');
    }

    public function equipment_list($page = 1, $size = 10, $paramer) {
        $map = array();
        /**
         * 搜索条件
         */
        $cols = 'id,imei,createtime';
        $order = 'id DESC';
        $total = $this->Equipment->where($map)->count();
        $list = $this->Equipment->field($cols)
                ->where($map)
                ->limit($size)
                ->page($page)
                ->order($order)
                ->select();
//        echo $this->Equipment->getLastSql();
        $list_info = array();
        foreach ($list as $k => $v) {
            $list_info[$k]['id'] = $v['id'];
            $list_info[$k]['imei'] = $v['imei'];
            $list_info[$k]['createtime'] = $v['createtime'];
        }
        $result = array(
            'list' => $list_info,
            'total' => $total
        );
        return $result;
    }

    /**
     * 新建回传设备
     */
    public function add_equipment($data = array()) {
        return $this->Equipment->add($data);
    }

    /**
     * 编辑回传设备
     */
    public function save_equipment($data = array()) {
        return $this->Equipment->save($data);
    }

    public function get_equipment($id) {
        return $this->Equipment->where(array('id' => $id))->find();
    }
}
